package com.cat.dataStructure;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/divide-intervals-into-minimum-number-of-groups/description/
 * @create 2025/8/24 15:03
 * @since JDK17
 */

public class Solution50 {
    static int[] diff = new int[1000001];
    public int minGroups(int[][] intervals) {
        Arrays.fill(diff, 0);
        int n = intervals.length, ans = 0, max = -1, sum = 0;
        for (int i = 0; i < n; i++) {
            diff[intervals[i][0]]++;
            diff[intervals[i][1] + 1]--;
            max = Math.max(intervals[i][1], max);
        }
        for (int i = 0; i <= max; i++) {
            sum += diff[i];
            ans = Math.max(ans, sum);
        }
        return ans;
    }
}
